package cn.otrue.patienthealthmanager.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;
import android.widget.Toast;
import cn.otrue.patienthealthmanager.R;
import cn.otrue.patienthealthmanager.adapter.CenterHelpAdpater;
import cn.otrue.patienthealthmanager.bean.TransferParameter;
import cn.otrue.patienthealthmanager.http.HttpCons;
import cn.otrue.patienthealthmanager.http.HttpServer;
import cn.otrue.patienthealthmanager.http.ServerHandler;

import com.google.gson.reflect.TypeToken;

/**
 * 个人中心->帮助中心
 * 
 * @author G
 * 
 */
public class CenterHelpActivity extends BaseActivity {
	private TextView tv_title_title, tv_title_back;
	private WebView lv_bangzhu;
	private CenterHelpAdpater adpater;
	final String mimeType = "text/html";
	final String encoding = "utf-8";
	private List<Map<String, String>> listMap= new ArrayList<Map<String,String>>();
	private Map<String, String> planList = new HashMap<String, String>();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_center_help);
		initView();

	}

	private void initView() {
		initTitleBar();
		 lv_bangzhu = (WebView) findViewById(R.id.lv_bangzhu);
	
	getDate();
	}

	
	private Handler Handler = new ServerHandler() {
	

	

		@Override
		public void onSuccess(Bundle data, String state, String msg) {

			String dataStr = data.getString(HttpCons.DATA);
			if (state.equals("001")) {
				planList = HttpServer.gson.fromJson(dataStr,
						new TypeToken<Map<String, String>>() {
						}.getType());
				
			
			
				String strS =	planList.get("content");
				StringBuilder cmdetail =new StringBuilder();
				
				cmdetail.append(strS);
				lv_bangzhu.loadDataWithBaseURL(null,cmdetail.toString(), "text/html", "utf-8",null);


				Toast.makeText(getApplicationContext(), msg, 0).show();

			} else {
				Toast.makeText(getApplicationContext(), msg, 0).show();

			}
		}

		@Override
		public void onFail(Bundle data, String state) {
		
			if (state.equals(HttpCons.STATE_EXCEPTION)) {
				// 代表进入状态STATE_EXCEPTION 网络异常
				Toast.makeText(CenterHelpActivity.this, "网络异常,请稍后重试",
						Toast.LENGTH_SHORT).show();

			} else if (state.equals(HttpCons.STATE_FORMAT_ERROR)) {
				// 代表进入STATE_FORMAT_ERROR(不是Json)
			} else {
				// 代表进入STATE_ANALYTICAL_ERROR(Json解析错误)

			}
		}
	};
	private void getDate(){
		
		
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("seq",1);
		TransferParameter parameter = new TransferParameter();
		parameter.setUsername("");
		parameter.setPassword("");
		parameter.setData(map);
		new HttpServer().post(
				HttpCons.QueryTelpCenter, parameter,
				Handler);

	}
	public void initTitleBar() {
		tv_title_title = (TextView) findViewById(R.id.tv_title_title);
		tv_title_title.setText(getString(R.string.help_center));
		tv_title_back = (TextView) findViewById(R.id.tv_title_back);
		tv_title_back.setVisibility(View.VISIBLE);
		tv_title_back.setOnClickListener(this);
		
	}

	@Override
	public void onClick(View arg0) {
		switch (arg0.getId()) {
		case R.id.tv_title_back:
			finish();
			break;
		}
	}

}
